package com.zhongshengnetwork.rightbe.common.card.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ScrollView;

/**
 * 傻*scrollView
 * 垂直viewpager和scrollview的滚动冲突解决
 */
public class FoolishScrollView extends ScrollView {

    private boolean isOverScroll = false;

    public FoolishScrollView(Context context) {
        super(context);
    }

    public FoolishScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
        isOverScroll = clampedY;
        super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if (!isOverScroll) { //通知ViewPager不要干扰自身的操作
            getParent().requestDisallowInterceptTouchEvent(true);
            return super.onTouchEvent(ev);
        } else {
            getParent().requestDisallowInterceptTouchEvent(false);
            return isOverScroll = false;//这里需要重置isOverScroll
        }
    }
}
